from manimlib import *
from manim._config.utils import ManimConfig
from numpy import square
import numpy as np

class Test(Scene):
    config.background_color=WHITE
    def construct(self):
        self.camera.background_color = WHITE
        def p1(x):
            return np.array([x,x*0.2+2,0])

        p_a=Point(p1(-3))
        p_b=Point(p1(0))
        p_c=Point(p1(3))
        t_a=Tex('A').next_to(p_a,UP)
        t_b=Tex('B').next_to(p_b,UP)
        t_c=Tex('C').next_to(p_c,UP)
        line1=Line(p1(-5),p1(5)).set_color(BLACK)

        def p2(x):
            return np.array([x,x*0.0001-3,0])

        p_d=Point(p2(-4))
        p_e=Point(p2(-1))
        p_f=Point(p2(4))
        t_d=Tex('D').next_to(p_d,DOWN)
        t_e=Tex('E').next_to(p_e,DOWN)
        t_f=Tex('F').next_to(p_f,DOWN)
        line2=Line(p2(-5),p2(5)).set_color(BLACK)

        ae=Line(p_a.get_center(),p_e.get_center())
        af=Line(p_a.get_center(),p_f.get_center())
        bd=Line(p_b.get_center(),p_d.get_center())
        bf=Line(p_b.get_center(),p_f.get_center())
        cd=Line(p_c.get_center(),p_d.get_center())
        ce=Line(p_c.get_center(),p_e.get_center())
        for i in [ae,af,bd,bf,cd,ce]:
            i.set_color(BLACK)
            self.add(i)
        print(line_intersection(ae.get_start_and_end(),bd.get_start_and_end()))
        p_g=Point(line_intersection(ae.get_start_and_end(),bd.get_start_and_end()))
        p_h=Point(line_intersection(bf.get_start_and_end(),ce.get_start_and_end()))
        p_i=Point(line_intersection(af.get_start_and_end(),cd.get_start_and_end()))
        t_g=Tex('G').next_to(p_g,LEFT)
        t_h=Tex('H').next_to(p_h,RIGHT)
        t_i=Tex('I').next_to(p_i,DOWN)
        line_mid=DashedLine(p_g.get_center(),p_h.get_center()).set_color(BLACK)
        self.add(p_a,p_b,p_c,line1,p_d,p_e,p_f,line2,line_mid,p_g,p_h,p_i)
        self.add(t_a,t_b,t_c,t_d,t_e,t_f,t_g,t_h,t_i)
        self.wait(0.03)
        # 2
        self.remove(line_mid)
        gh=Line(p_g.get_center(),p_h.get_center()).set_color(BLACK)
        t_i.become(Tex(r'I^\prime').next_to(p_i,DOWN))
        
        ad=DashedLine(p_a.get_center(),p_d.get_center())
        ah=DashedLine(p_a.get_center(),p_h.get_center())
        fc=DashedLine(p_f.get_center(),p_c.get_center())
        fg=DashedLine(p_f.get_center(),p_g.get_center())
        for i in [ad,ah,fc,fg]:
            i.set_color(BLACK)
            self.add(i)
        self.add(gh)
        self.wait(0.03)
        # 3
        self.remove(ah,fg)
        t_i.become(Tex(r'I^{\prime\prime}').next_to(p_i,DOWN))

        cg=DashedLine(p_c.get_center(),p_g.get_center())
        dh=DashedLine(p_d.get_center(),p_h.get_center())
        for i in [cg,dh]:
            i.set_color(BLACK)
            self.add(i)
        self.wait(0.03)